package cn.lhjl.day07.practice;

import java.util.HashMap;
import java.util.Map;

public class 计算字符串中的单词数 {
    public static void main(String[] args) {
        String string = "The Apache Tomcat Project is proud to announce the release of version 8.5.47 of Apache Tomcat. Apache Tomcat 8.5.x replaces 8.0.x and includes new features pulled forward from Tomcat 9.0.x. The minimum Java version and implemented specification versions remain unchanged. The notable changes compared to 8.5.46 include";
        char[] chars = string.toCharArray();
        int head =0;
        Map<String,Integer> map = new HashMap<>();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i]==32){
                String str = string.substring(head, i);
                if (map.containsKey(str)){
                    Integer value = map.get(str);
                    value++;
                    map.put(str,value);
                }else{
                    map.put(str,1);
                }
                head=i+1;

            }
        }
        System.out.println(map);
    }
}
